package org.spring.springboot.exception.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.springboot.exception.common.ascept.Result;
import org.spring.springboot.exception.common.selfex.BusinessException;
import org.spring.springboot.exception.domain.City;
import org.spring.springboot.exception.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by bysocket on 07/02/2017.
 */
@RestController
public class CityRestController {
	
	private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private CityService cityService;

    @RequestMapping(value = "/api/city", method = RequestMethod.GET)
    public Result<City> findOneCity(@RequestParam(value = "cityName", required = true) String cityName,HttpServletRequest request) throws BusinessException {
    	
    	logger.info(cityName);
        return cityService.findCityByName(cityName);
    }
    
    @RequestMapping(value = "/api/citys", method = RequestMethod.GET)
    public Result<Map<String, String>> findCitys() throws BusinessException {
    	
    	return cityService.findCitys();
    }


}
